package com.pig.service.impl;

import com.pig.annotation.RequiredLog;
import com.pig.dao.AdminMapper;
import com.pig.pojo.user.Admin;
import com.pig.service.AdminService;
import com.pig.util.SysResultLayui;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    /**分页查询展现管理员*/
    @RequiredLog(operation = "分页查询管理员信息")
    @Override
    public SysResultLayui findAdminByPage(int page, int limit) {
        int startIndex = (page-1)*limit;
        int count = adminMapper.selectCount(null);
        List<Admin> itemList = adminMapper.findAdminByPage(startIndex,limit);
        return new SysResultLayui(200, "ok", count, itemList);
    }
    /**添加管理员
     * @return*/
    @Override
    @RequiredLog(operation = "添加管理员信息")
    public void saveAdmin(Admin admin) {
         String password = admin.getPassword();
         String pwd = DigestUtils.md5DigestAsHex(password.getBytes());
         admin.setPassword(pwd);
         admin.setStatus(1l);
         admin.setRoleId(47l);
         int a = adminMapper.saveAdmin(admin);
    }
    /**查看数据库是否有相同管理员*/
    @Override
    public Admin FindByAdminName(String username) {

        System.out.println(username);
        return adminMapper.FindByAdminName(username);
    }
    /**根据id改变管理员状态*/
    @Override
    public SysResultLayui<Admin> updateAdminStatusById(int id, int status) {
        adminMapper.updateAdminStatusById(id,status);
        return SysResultLayui.success();
    }
}
